package oj;

import java.util.HashSet;
import java.util.Set;

public class LC523 {
    public boolean checkSubarraySum(int[] nums, int k) {
        int n=nums.length;
        int[] arr=new int[n+1];
        for(int i=1;i<=n;i++){
            arr[i]=arr[i-1]+nums[i-1];
        }
        Set<Integer> set=new HashSet<>();
        for(int i=2;i<=n;i++){
            set.add(arr[i-2]%k);
            if(set.contains(arr[i]%k)){
                return true;
            }
        }
        return false;
    }
}
